1
2
3
4
5
6
7
8
9
10
11
12 package com.aimedia.ui;
13
14 import java.awt.event.*;
15
16 import javax.swing.*;
17
18 import org.apache.log4j.Logger;
19
20 /***
21 * Generic Action implementation for cancelling a UI action.
22 * @author Chris Rose
23 */
24 public class CancelAction extends AbstractAction {
25 /***
26 * Logger for this class
27 */
28 private static final Logger logger = Logger.getLogger(CancelAction.class);
29
30 private ICancellable target;
31
32 /***
33 * Create a new cancel action handling the supplied target.
34 * @param target the <code>ICancellable</code> that will receive the cancel
35 * action
36 */
37 public CancelAction(ICancellable target) {
38 super("Cancel");
39 putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_C));
40 if (null == target) {
41 throw new IllegalArgumentException("Must have a non-null target");
42 }
43 this.target = target;
44 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
45 }
46
47
48
49
50 public void actionPerformed(ActionEvent e) {
51 if (logger.isDebugEnabled()) {
52 logger.debug("actionPerformed() - doCancel invoked on " + target.getClass().getName());
53 }
54
55 target.doCancel();
56 }
57
58 }